// miniprogram/pages/detail/detail.js
// import parser from 'rich-text-parser'
Page({
  data: {
    id: '',
    detail: '',
    audioCtx: '',
    control: 'stop',
    html2: ''
  },

  onLoad: function (options) {
    this._options = options
    this.getQuestionDetail()
  },
  handleControl() {

  },
  setContent(str) {
    let str1 = str.replace(/<p([\s\w"=\/\.:;]+)((?:(style="[^"]+")))/ig, '<p')
      .replace(/<p([\s\w"=\/\.:;]+)((?:(class="[^"]+")))/ig, '<p')
      .replace(/<p>/ig, '<p class="p_class">')
      .replace(/one-icon one-icon-quote one_quote/ig, 'iconfont icon-quote')

    
      .replace(/<img([\s\w"-=\/\.:;]+)((?:(height="[^"]+")))/ig, '<img$1')
      .replace(/<img([\s\w"-=\/\.:;]+)((?:(width="[^"]+")))/ig, '<img$1')
      .replace(/<img([\s\w"-=\/\.:;]+)((?:(style="[^"]+")))/ig, '<img$1')
      .replace(/<img([\s\w"-=\/\.:;]+)((?:(alt="[^"]+")))/ig, '<img$1')
      .replace(/<img([\s\w"-=\/\.:;]+)/ig, '<img$1 class="pho"')
    // console.log(str1)
    return str1
  },
  
  getQuestionDetail() {
    wx.cloud.callFunction({
      name: 'read',
      data: {
        $url: 'questionDetail',
        id: this._options.id
      }
    }).then(res => {
      let detail = res.result.data


      detail.answer_content = this.setContent(detail.answer_content)
      // 定义需要解析的特殊标签，value不填默认是div
      // parser.definedCustomTag({ figure: 'div', figcaption: '' })
      // const nodes = parser.getRichTextJson(detail.answer_content)
      // console.log(nodes)
      // this.setData({
      //   html2: nodes.children
      // })
      
      this.setData({
        detail: detail
      })
    })
  }

})